// /**
//  * Copyright © 2013-2017 Magento, Inc. All rights reserved.
//  * See COPYING.txt for license details.
//  */

//
//  Framework grid generation
//  _____________________________________________

.make-grid-columns() {

    //  Common styles for all sizes of grid columns, widths 1-12

    .col(@index) {
        //  Initial
        @item: ~'.col-xs-@{index}, .col-m-@{index}, .col-l-@{index}, .col-xl-@{index}';
        .col((@index + 1), @item);
    }

    .col(@index, @list) when (@index =< @grid-columns) {
        //  General; '=<' isn't a typo
        @item: ~'.col-xs-@{index}, .col-m-@{index}, .col-l-@{index}, .col-xl-@{index}';
        .col((@index + 1), ~'@{list}, @{item}');
    }

    .col(@index, @list) when (@index > @grid-columns) {
        //  Terminal
        @{list} {
            position: relative;
            //  Prevent columns from collapsing when empty
            min-height: 1px;
            //  Inner gutter via padding
            padding-left: (@grid-gutter-width / 2);
            padding-right: (@grid-gutter-width / 2);
        }
    }

    .col(1); //  Kickstart it
}

.float-grid-columns(@class) {

    .col(@index) {
        //  Initial
        @item: ~'.col-@{class}-@{index}';
        .col((@index + 1), @item);
    }

    .col(@index, @list) when (@index =< @grid-columns) {
        //  General
        @item: ~'.col-@{class}-@{index}';
        .col((@index + 1), ~'@{list}, @{item}');
    }

    .col(@index, @list) when (@index > @grid-columns) {
        //  Terminal
        @{list} {
            float: left;
        }
    }

    .col(1); //  Kickstart it
}

.calc-grid-column(@index, @class, @type) when (@type = width) and (@index > 0) {
    .col-@{class}-@{index} {
        width: percentage((@index / @grid-columns));
    }
}

.calc-grid-column(@index, @class, @type) when (@type = push) and (@index > 0) {
    .col-@{class}-push-@{index} {
        left: percentage((@index / @grid-columns));
    }
}

.calc-grid-column(@index, @class, @type) when (@type = push) and (@index = 0) {
    .col-@{class}-push-0 {
        left: auto;
    }
}

.calc-grid-column(@index, @class, @type) when (@type = pull) and (@index > 0) {
    .col-@{class}-pull-@{index} {
        right: percentage((@index / @grid-columns));
    }
}

.calc-grid-column(@index, @class, @type) when (@type = pull) and (@index = 0) {
    .col-@{class}-pull-0 {
        right: auto;
    }
}

.calc-grid-column(@index, @class, @type) when (@type = offset) {
    .col-@{class}-offset-@{index} {
        margin-left: percentage((@index / @grid-columns));
    }
}

//  Basic looping in LESS

.loop-grid-columns(@index, @class, @type) when (@index >= 0) {
    .calc-grid-column(@index, @class, @type);
    //  Next iteration
    .loop-grid-columns((@index - 1), @class, @type);
}

//  Create grid for specific class

.make-grid(@class) {
    .float-grid-columns(@class);
    .loop-grid-columns(@grid-columns, @class, width);
    .loop-grid-columns(@grid-columns, @class, pull);
    .loop-grid-columns(@grid-columns, @class, push);
    .loop-grid-columns(@grid-columns, @class, offset);
}
